package com.pagemodel.login;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CheckUsername
 */
@WebServlet("/checkUsernameAction")
public class CheckUsernameAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckUsernameAction() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setHeader("content-type","text/html;charset=UTF-8");//防止乱码
		response.setCharacterEncoding("UTF-8"); //防止乱码

		String  user =request.getParameter("user"); //getParameter对应的是jsp中的name值
		
		PrintWriter out = response.getWriter();
		if(user==null||user.isEmpty()) {
			out.println("用户名不能为空");
		}else {
			if("ganhx".equals(user)) {
				out.println("该用户名已被使用,请换一个！");
			}else{
				out.println("该用户名未被使用，可以注册！");
			}
		}
	}

}
